#include "Project_main4.h"



extern unsigned char IP_Hao;
uint8_t max_Th4 = 0;
uint8_t max_Tl4 = 0;
extern uint8_t max_num4;

void get_temp4(void)
{
	float temp;
    uint8_t temp_buff[max_Th4][max_Tl4][2];
//    uint8_t temp_buff[30][4][2];
    for (int i = 0; i < max_Th4; i++) {
        for (int j = 0; j < max_Tl4; j++) {
            for (int k = 0; k < 2; k++) {
                temp_buff[i][j][k] = 0xff;
            }
        }
    }

    GXHT4W_Search_Rom();
	if(max_num4 != GXHT4W_SensorNum)
	{
		get_Search4(&max_num4);
	}

    for (int num = 0; num < GXHT4W_SensorNum; num++) {
		GXHT4W_change_Temp(ucGXHT4WId[num]);
    }
	OneWire4_UP_1;
	delay_ms(800);
	OneWire4_UP_0;
	//----------------------------------------------------------
	    for (int num = 0; num < GXHT4W_SensorNum; num++) {

//				readT = 0;
				temp = GXHT4W_Read_Temp(ucGXHT4WId[num], &GXHT4W_Th, &GXHT4W_Tl);
				temp_buff[GXHT4W_Th - 1][GXHT4W_Tl - 1][0] = temp;
				temp_buff[GXHT4W_Th - 1][GXHT4W_Tl - 1][1] = temp * 100 - (int)temp * 100;
				OLED_ShowNum(2, 1, temp, 3);
				OLED_ShowChar(2, 4, '.');
				OLED_ShowNum(2, 5, temp * 100 - (int)temp * 100, 2);
				OLED_ShowNum(3, 1, GXHT4W_Th, 2);
				OLED_ShowNum(3, 7, GXHT4W_Tl, 2);
				OLED_ShowNum(4, 1, max_Th4, 5);
				OLED_ShowNum(4, 7, max_Tl4, 5);
//				delay_ms(2);
		
    }
    for (int i = 0; i < max_Th4; i++) {
        for (int j = 0; j < max_Tl4; j++) {
            for (int k = 0; k < 2; k++) {
                UART1Send(temp_buff[i][j][k]);
            }
        }
    }
}

void get_Search4(uint8_t *xh)
{
	float temp;
    GXHT4W_Search_Rom();

    for (int num = 0; num < GXHT4W_SensorNum; num++) {
		GXHT4W_change_Temp(ucGXHT4WId[num]);
    }
	OneWire4_UP_1;
	delay_ms(800);
	OneWire4_UP_0;
	//----------------------------------------------------------
	    for (int num = 0; num < GXHT4W_SensorNum; num++) {
				temp = GXHT4W_Read_Temp(ucGXHT4WId[num], &GXHT4W_Th, &GXHT4W_Tl);
				OLED_ShowNum(2, 1, temp, 3);
				OLED_ShowChar(2, 4, '.');
				OLED_ShowNum(2, 5, temp * 100 - (int)temp * 100, 2);
				OLED_ShowNum(3, 1, GXHT4W_Th, 2);
				OLED_ShowNum(3, 7, GXHT4W_Tl, 2);
				OLED_ShowNum(4, 1, max_Th4, 5);
				OLED_ShowNum(4, 7, max_Tl4, 5);
//						delay_ms(50);
				if (GXHT4W_Th > max_Th4) {
					max_Th4 = GXHT4W_Th;
				}
		
				if (GXHT4W_Tl > max_Tl4) {
					max_Tl4 = GXHT4W_Tl;
				}
		
    }
	//------------------------------------------------------------
	*xh = GXHT4W_SensorNum;
	OLED_ShowNum(1, 1, GXHT4W_SensorNum, 3);
}


